// *** LICENSE HEADER ***
// Filename: ./gui.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_GUI_H
#define NODEWARS_GUI_H

#include "SDL.h"
#include "guielement.h"
#include "button.h"
#include "label.h"
#include "numberfield.h"
#include "textfield.h"
#include "colorselect.h"
#include "colorviewer.h"
#include "canvas.h"
#include "toggle.h"
#include "engine.h"

class guielement;
class engine;

//Class for providing various gui functionality in the game
class gui{
    public:
        gui(engine* newParent);
        ~gui();

        //Called when a point is clicked in the game
        void Click(int x, int y);
        //Called upon a release of the mouse on a certain point in the game
        void Release(int x, int y);
        //Activates the given gui element
        void Activate(int id);
        //Delivers the pressed key to the active gui element
        void KeyPress(SDLKey key, char c);

        //Sets the gui callback function
        void SetCallback(void (&newCallback)(engine*, int));
        //Creation functions for creating various gui elements
        void CreateButton(int x, int y, int w, int h, const char* text, int id = 1);
        void CreateLabel(int x, int y, int fontSize, const char* text, int id = 1);
        void CreateNumberField(int x, int y, int w, int h, const char* text, int fontHeight, int maxval, int maxlen, int id = 1);
        void CreateTextField(int x, int y, int w, int h, const char* text, int fontHeight, int maxlen, int id = 1);
        void CreateColorSelector(int x, int y, int selection, int id = 1);
        void CreateColorViewer(int x, int y, int w, int h, int id = 1);
        void CreateCanvas(int x, int y, int w, int h, int id = 1);
        void CreateToggle(int x, int y, bool init, int id = 1);

        //Removes element by its ID
        void RemoveElement(int id);

        //Sets element's enabled status
        void SetElementEnabled(bool newEnabled, int id);
        //Sets element's text
        void SetElementText(const char* newText, int id);

        //Returns pointer to the gui element
        guielement* GetElement(int id);

        //Deletes all the gui elements
        void Flush();

        //Draws the gui on the screen
        void Draw();
    private:
        //Parent of this object
        engine* parent;
        //Linked list of the gui elements
        guielement* first;
        guielement* last;

        //Last activated gui element that will receive key presses
        guielement* lastActivated;

        //Adds a gui element to the linked list
        void push_backElement(guielement*);

        //Callback function for the element events
        void (*guiHandlerCallback)(engine* owner, int elementId);
};

#endif
